<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="out">
            <h3 style="margin-bottom:30px">请登录</h3>
            <el-form-item label="账号" prop="name" label-width="50px">
                <el-input v-model="ruleForm.name" placeholder="请输入账号" clearable></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password" label-width="50px">                    
                <el-input v-model="ruleForm.password" type="password" placeholder="请输入密码" show-password></el-input>
                </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
        </el-form>

        <el-dialog title="提示" width="20%" :visible.sync="dialogVisible">
            <span>请输入账号和密码</span>
            <span slot="footer">
                <el-button type="primary" @click="dialogVisible=false">确定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name:"Login",
        data(){
            return{
                dialogVisible:false,
                ruleForm: {
                    name: '',
                    password: '',
                },
                rules: {
                name: [
                    { required: true, message: '请输入账号', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' }
                ]
                }
            };
            },
            methods: {
                submitForm(formName) {
                    this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$router.push("/main");
                    } else {
                        console.log(valid);
                        this.dialogVisible=true;
                        return false;
                    }
                    });
                },
                resetForm(formName) {
                    this.$refs[formName].resetFields();
                }
            }
        }
</script>
<style lang="css" scoped>
    .out{
        display: block;
        border:1px solid #bbb;
        border-radius: 5px;
        padding: 35px 35px 35px 35px;
        max-width:300px;
        margin: 120px auto;
    }
    .conponent{
        border:1px solid #bbb;
    }
</style>
